<template>
  <div class="page-header">
    <div class="header-content">
      <div class="title-section">
        <div class="title-wrapper">
          <el-button v-if="$attrs.onBack" link class="back-button" @click="$emit('back')">
            <el-icon><el-icon-back /></el-icon>
          </el-button>
          <div class="title">
            <slot name="title">{{ title }}</slot>
          </div>
          <div class="title-actions">
            <slot name="title-actions"></slot>
          </div>
        </div>
        <div v-if="description" class="description">
          <el-icon class="info-icon"><InfoFilled /></el-icon>
          {{ description }}
        </div>
      </div>
      <div class="extra">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { InfoFilled } from '@element-plus/icons-vue'
import { Back as ElIconBack } from '@element-plus/icons-vue'

defineProps<{
  title: string
  description?: string
}>()

defineEmits<{
  (e: 'back'): void
}>()
</script>

<style scoped lang="scss">
.page-header {
  background-color: #fff;
  padding: 16px 24px;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  margin-bottom: 16px;

  .header-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;

    .title-section {
      flex: 1;
      margin-right: 48px;

      .title-wrapper {
        display: flex;
        align-items: center;
        margin-bottom: 4px;

        .back-button {
          margin-right: 8px;
          padding: 0;
          height: 32px;
          color: var(--el-text-color-regular);
          display: inline-flex;
          align-items: center;
          justify-content: center;

          &:hover {
            color: var(--el-color-primary);
          }
        }
      }

      .title {
        font-size: 20px;
        font-weight: 500;
        color: var(--el-text-color-primary);
        line-height: 32px;
      }

      .title-actions {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-left: auto;

        :deep(.el-button) {
          height: 32px;
          padding: 8px 16px;
          font-size: 13px;
          border-radius: 4px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 4px;
          line-height: 1;

          .el-icon {
            margin: 0;
          }

          span {
            line-height: 1;
          }
        }
      }

      .description {
        margin-top: 4px;
        font-size: 14px;
        color: var(--el-text-color-secondary);
        line-height: 1.5;
        display: flex;
        align-items: flex-start;
        gap: 4px;

        .info-icon {
          margin-top: 3px;
          color: var(--el-color-info);
          font-size: 14px;
        }
      }
    }

    .extra {
      display: flex;
      gap: 12px;
      align-items: center;
      flex-shrink: 0;

      :deep(.search-input) {
        width: 240px;
      }
    }
  }
}
</style>
